﻿using System;
using System.Data;
using System.Collections.Generic;
using Royalsoft.Common;
using NJL.Model;
using NJL.DALFactory;
using NJL.IDAL;
namespace NJL.BLL
{
	/// <summary>
	/// NJL_SYS_CS_CONTACT_TYPE
	/// </summary>
	public partial class NJL_SYS_CS_CONTACT_TYPE
	{
		private readonly INJL_SYS_CS_CONTACT_TYPE dal=DataAccess.CreateNJL_SYS_CS_CONTACT_TYPE();
		public NJL_SYS_CS_CONTACT_TYPE()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string TYPE_CODE)
		{
			return dal.Exists(TYPE_CODE);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(NJL.Model.NJL_SYS_CS_CONTACT_TYPE model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(NJL.Model.NJL_SYS_CS_CONTACT_TYPE model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string TYPE_CODE)
		{
			
			return dal.Delete(TYPE_CODE);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string TYPE_CODElist )
		{
			return dal.DeleteList(TYPE_CODElist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NJL.Model.NJL_SYS_CS_CONTACT_TYPE GetModel(string TYPE_CODE)
		{
			
			return dal.GetModel(TYPE_CODE);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public NJL.Model.NJL_SYS_CS_CONTACT_TYPE GetModelByCache(string TYPE_CODE)
		{
			
			string CacheKey = "NJL_SYS_CS_CONTACT_TYPEModel-" + TYPE_CODE;
			object objModel = Royalsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(TYPE_CODE);
					if (objModel != null)
					{
						int ModelCache = Royalsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Royalsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (NJL.Model.NJL_SYS_CS_CONTACT_TYPE)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<NJL.Model.NJL_SYS_CS_CONTACT_TYPE> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<NJL.Model.NJL_SYS_CS_CONTACT_TYPE> DataTableToList(DataTable dt)
		{
			List<NJL.Model.NJL_SYS_CS_CONTACT_TYPE> modelList = new List<NJL.Model.NJL_SYS_CS_CONTACT_TYPE>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				NJL.Model.NJL_SYS_CS_CONTACT_TYPE model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new NJL.Model.NJL_SYS_CS_CONTACT_TYPE();
					if(dt.Rows[n]["TYPE_CODE"]!=null && dt.Rows[n]["TYPE_CODE"].ToString()!="")
					{
					model.TYPE_CODE=dt.Rows[n]["TYPE_CODE"].ToString();
					}
					if(dt.Rows[n]["TYPE_NAME"]!=null && dt.Rows[n]["TYPE_NAME"].ToString()!="")
					{
					model.TYPE_NAME=dt.Rows[n]["TYPE_NAME"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

